package com.hbnu.mapper;

import com.hbnu.pojo.Collection;
import com.hbnu.pojo.Good;
import com.hbnu.pojo.Order;
import com.hbnu.pojo.Refund;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("insert into order_detail (oid, state, time, payment, address, discount, tolPrice) " +
            "value (#{oid},#{state},#{time},#{payment},#{address},#{discount},#{tolPrice})")
    void insertOrderDetail(String oid, Integer state, LocalDateTime time, BigDecimal payment, String address, BigDecimal discount, BigDecimal tolPrice);

    @Insert("insert into order_goods (oid, gid, count) " +
            "value (#{oid},#{gid},#{count})")
    void insertOrderGoods(String oid,String gid,Integer count);


    @Insert("insert into order_user (oid, uid) " +
            "value (#{oid},#{uid})")
    void insertOrderUser(String oid,String uid);

    @Insert("insert into refund (oid, uid, reason, agree) " +
            "value (#{oid},#{uid},#{reason},#{agree})")
    void insertRefund(String oid,String uid,String reason,Integer agree);

    @Delete("delete from cart where uid=#{uid} and gid=#{gid}")
    void deleteCart(String uid,String gid);

    @Update("update order_detail set state=#{state} where oid=#{oid}")
    void updateOrderState(String oid,Integer state);

    @Update("update order_detail set address=#{address} where oid=#{oid}")
    void updateOrderAddress(String oid,String address);

    @Update("update order_detail set time=#{time} where oid=#{oid}")
    void updateOrderTime(String oid,LocalDateTime time);

    @Update("update order_detail set eid=#{eid},company=#{company} where oid=#{oid}")
    void updateOrderEidAndCompany(String oid,String eid,String company);

    @Update("update good set num=num-#{count} where gid=#{gid}")
    void updateGoodNum(String gid,Integer count);
    @Update("update refund set agree=#{agree} where oid=#{oid}")
    void updateRefund(Integer agree,String oid);

    @Update("update refund set reason=#{reason} where oid=#{oid}")
    void updateRefundReason(String reason,String oid);
    @Select("select * from order_detail where oid=#{oid}")
    Order getOrderDetail(String oid);

    @Select("select * from order_detail")
    List<Order> getOrderList();

    @Select("select oid from order_detail")
    List<String> getOidList();

    @Select("select oid from order_detail where oid like '%' #{content} '%'")
    List<String> getOidListByContent(String content);
    @Select("select oid from order_user where uid=#{uid}")
    List<String> getOrderListByUid(String uid);

    @Select("select order_detail.oid from order_user,order_detail where order_detail.oid=order_user.oid and uid=#{uid} and state=#{state}")
    List<String>getOrderListByUidAndState(String uid,Integer state);

    @Select("select oid from order_detail where state=#{state} and (oid like '%' #{content} '%')")
    List<String> getOrderListByStateAndContent(String content, Integer state);
    @Select(("select * from order_goods where oid=#{oid}"))
    List<Collection> getGoodsListByOid(String oid);

    @Select("select * from good where gid=#{gid}")
    Good getGoodByGid(String gid);

    @Select("select * from refund where oid like '%' #{content} '%' ")
    List<Refund> getRefundListByContent(String content);

    @Select("select * from refund where (oid like '%' #{content} '%') and agree=#{agree}")
    List<Refund> getRefundListByAgreeAndContent(String content,Integer agree);

    @Select("select * from refund where oid=#{oid}")
    Refund getRefundByOid(String oid);

}
